package cn.wzvtc.soft14.Service;

import cn.wzvtc.soft14.domian.publish;
import cn.wzvtc.soft14.repository.PublisPepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by asus on 2016/6/23.
 */
@Service
public class PublishService {
    @Autowired
    private PublisPepo publisPepo;

    public List publishSelect(String studentId) {
        return this.publisPepo.findByStudentId(studentId);
    }

    public int publishCount(String studentId) {
        List<publish> result = publisPepo.findByStudentId(studentId);
        return result.size();
    }

    public publish savepublish(publish pu) {
        return publisPepo.save(pu);
    }

    @Transactional
    public boolean deleteUser(publish pu) {
        List<publish> publishlist = publisPepo.findByStudentId(pu.getStudentId());
        for (publish publish1 : publishlist) {
            publisPepo.delete(publish1);
        }
        /*publish publishlist = publishPepo.findByStudentId(pu.getStudentId());
        Field[] fields=publishlist.getClass().getDeclaredFields();
        for(Field publish1 :fields)
        {
            publishPepo.delete(String.valueOf(publish1));
        }*/
        return true;
    }

}
